﻿#define DEBUGLOG
using System;
using System.Collections.Generic;
using System.Collections;
using System.Data;
using System.Data.Common;
using System.Text;
using System.Data.OracleClient;
using System.Data.OleDb;
using System.Data.SqlClient;
using System.Reflection;
using Maticsoft.DBUtility;//请先添加引用
using GMS.Model;
//using GMS.Utils;

namespace GMS.DAL
{
    /// <summary>
    /// 数据访问类FilesDB。
    /// </summary>
    public class FilesDBDALAccess
    {
        public FilesDBDALAccess() { }
        #region  成员方法

        private object GetValidValue(object obj)
        {
            if (obj != null)
                return obj;
            else
                return DBNull.Value;
        }

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(string AUTOID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from TAB_FILESDB");
            strSql.Append(" where AUTOID=:AUTOID ");
            OracleParameter[] parameters = {
					new OracleParameter(":AUTOID", OracleType.VarChar,50)};
            parameters[0].Value = AUTOID;

            return DbHelperOra.Exists(strSql.ToString(), parameters);
        }


        /// <summary>
        /// 增加一条数据
        /// </summary>
        public void Add(GMS.Model.FilesDB model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into TAB_FILESDB(");
            strSql.Append("AUTOID,DEPT,CREATOR,TITLE,FILENO,CREATEDT,FILETYPE,BELONGID,BELONGTABLE,FILECONTENT,FILENAME,FILEPATH,FILESUFFIX,UNIQUENO,FLAG,UPDATOR,UPDATEDT,ATTRIBUTE1,ATTRIBUTE2,CITYCODE)");
            strSql.Append(" values (");
            strSql.Append(":AUTOID,:DEPT,:CREATOR,:TITLE,:FILENO,:CREATEDT,:FILETYPE,:BELONGID,:BELONGTABLE,:FILECONTENT,:FILENAME,:FILEPATH,:FILESUFFIX,:UNIQUENO,:FLAG,:UPDATOR,:UPDATEDT,:ATTRIBUTE1,:ATTRIBUTE2,:CITYCODE)");
            OracleParameter[] parameters = {
					new OracleParameter(":AUTOID", OracleType.VarChar,20),
					new OracleParameter(":DEPT", OracleType.VarChar,100),
					new OracleParameter(":CREATOR", OracleType.VarChar,30),
					new OracleParameter(":TITLE", OracleType.VarChar,100),
					new OracleParameter(":FILENO", OracleType.VarChar,50),
					new OracleParameter(":CREATEDT", OracleType.DateTime),
					new OracleParameter(":FILETYPE", OracleType.VarChar,20),
					new OracleParameter(":BELONGID", OracleType.VarChar,20),
					new OracleParameter(":BELONGTABLE", OracleType.VarChar,100),
					new OracleParameter(":FILECONTENT", OracleType.Blob),
					new OracleParameter(":FILENAME", OracleType.VarChar,300),
					new OracleParameter(":FILEPATH", OracleType.VarChar,400),
					new OracleParameter(":FILESUFFIX", OracleType.VarChar,20),
					new OracleParameter(":UNIQUENO", OracleType.VarChar,100),
					new OracleParameter(":FLAG", OracleType.Char,1),
                    new OracleParameter(":UPDATOR", OracleType.VarChar,30),
                    new OracleParameter(":UPDATEDT", OracleType.DateTime),
					new OracleParameter(":ATTRIBUTE1", OracleType.VarChar,100),
					new OracleParameter(":ATTRIBUTE2", OracleType.VarChar,100),
                    new OracleParameter(":CITYCODE", OracleType.VarChar,30)
            };
            parameters[0].Value = GetValidValue(model.AUTOID);
            parameters[1].Value = GetValidValue(model.DEPT);
            parameters[2].Value = GetValidValue(model.CREATOR);
            parameters[3].Value = GetValidValue(model.TITLE);
            parameters[4].Value = GetValidValue(model.FILENO);
            parameters[5].Value = GetValidValue(model.CREATEDT);
            parameters[6].Value = GetValidValue(model.FILETYPE);
            parameters[7].Value = GetValidValue(model.BELONGID);
            parameters[8].Value = GetValidValue(model.BELONGTABLE);
            parameters[9].Value = GetValidValue(model.FILECONTENT);
            parameters[10].Value = GetValidValue(model.FILENAME);
            parameters[11].Value = GetValidValue(model.FILEPATH);
            parameters[12].Value = GetValidValue(model.FILESUFFIX);
            parameters[13].Value = GetValidValue(model.UNIQUENO);
            parameters[14].Value = GetValidValue(model.FLAG);
            parameters[15].Value = GetValidValue(model.UPDATOR);
            parameters[16].Value = GetValidValue(model.UPDATEDT);
            parameters[17].Value = GetValidValue(model.ATTRIBUTE1);
            parameters[18].Value = GetValidValue(model.ATTRIBUTE2);
            parameters[19].Value = GetValidValue(model.CITYCODE);


            DbHelperOra.ExecuteSql(strSql.ToString(), parameters);
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public void Update(GMS.Model.FilesDB model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update TAB_FILESDB set ");
            strSql.Append("DEPT=:DEPT,");
            strSql.Append("CREATOR=:CREATOR,");
            strSql.Append("TITLE=:TITLE,");
            strSql.Append("FILENO=:FILENO,");
            strSql.Append("CREATEDT=:CREATEDT,");
            strSql.Append("FILETYPE=:FILETYPE,");
            strSql.Append("BELONGID=:BELONGID,");
            strSql.Append("BELONGTABLE=:BELONGTABLE,");
            strSql.Append("FILECONTENT=:FILECONTENT,");
            strSql.Append("FILENAME=:FILENAME,");
            strSql.Append("FILEPATH=:FILEPATH,");
            strSql.Append("FILESUFFIX=:FILESUFFIX,");
            strSql.Append("UNIQUENO=:UNIQUENO,");
            strSql.Append("FLAG=:FLAG,");
            strSql.Append("UPDATOR=:UPDATOR,");
            strSql.Append("UPDATEDT=:UPDATEDT,");
            strSql.Append("ATTRIBUTE1=:ATTRIBUTE1,");
            strSql.Append("ATTRIBUTE2=:ATTRIBUTE2");
            strSql.Append("ATTRIBUTE2=:CITYCODE");
            strSql.Append(" where AUTOID=:AUTOID ");
            OracleParameter[] parameters = {
					new OracleParameter(":AUTOID", OracleType.VarChar,30),
					new OracleParameter(":DEPT", OracleType.VarChar,100),
					new OracleParameter(":CREATOR", OracleType.VarChar,50),
					new OracleParameter(":TITLE", OracleType.VarChar,100),
					new OracleParameter(":FILENO", OracleType.VarChar,50),
					new OracleParameter(":CREATEDT", OracleType.DateTime),
					new OracleParameter(":FILETYPE", OracleType.VarChar,20),
					new OracleParameter(":BELONGID", OracleType.VarChar,30),
					new OracleParameter(":BELONGTABLE", OracleType.VarChar,100),
					new OracleParameter(":FILECONTENT", OracleType.Blob),
					new OracleParameter(":FILENAME", OracleType.VarChar,300),
					new OracleParameter(":FILEPATH", OracleType.VarChar,400),
					new OracleParameter(":FILESUFFIX", OracleType.VarChar,20),
					new OracleParameter(":UNIQUENO", OracleType.VarChar,100),
					new OracleParameter(":FLAG", OracleType.Char,1),
					new OracleParameter(":UPDATOR", OracleType.VarChar,50),
					new OracleParameter(":UPDATEDT", OracleType.DateTime),
					new OracleParameter(":ATTRIBUTE1", OracleType.VarChar,100),
					new OracleParameter(":ATTRIBUTE2", OracleType.VarChar,100),
            new OracleParameter(":CITYCODE", OracleType.VarChar,30)};
            parameters[0].Value = GetValidValue(model.AUTOID);
            parameters[1].Value = GetValidValue(model.DEPT);
            parameters[2].Value = GetValidValue(model.CREATOR);
            parameters[3].Value = GetValidValue(model.TITLE);
            parameters[4].Value = GetValidValue(model.FILENO);
            parameters[5].Value = GetValidValue(model.CREATEDT);
            parameters[6].Value = GetValidValue(model.FILETYPE);
            parameters[7].Value = GetValidValue(model.BELONGID);
            parameters[8].Value = GetValidValue(model.BELONGTABLE);
            parameters[9].Value = GetValidValue(model.FILECONTENT);
            parameters[10].Value = GetValidValue(model.FILENAME);
            parameters[11].Value = GetValidValue(model.FILEPATH);
            parameters[12].Value = GetValidValue(model.FILESUFFIX);
            parameters[13].Value = GetValidValue(model.UNIQUENO);
            parameters[14].Value = GetValidValue(model.FLAG);
            parameters[15].Value = GetValidValue(model.UPDATOR);
            parameters[16].Value = GetValidValue(model.UPDATEDT);
            parameters[17].Value = GetValidValue(model.ATTRIBUTE1);
            parameters[18].Value = GetValidValue(model.ATTRIBUTE2);
            parameters[19].Value = GetValidValue(model.CITYCODE);

            DbHelperOra.ExecuteSql(strSql.ToString(), parameters);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public void Delete(string AUTOID)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from TAB_FILESDB1 ");
            strSql.Append(" where AUTOID=@AUTOID ");
            OleDbParameter[] parameters = {
					new OleDbParameter("@AUTOID", OleDbType.VarChar,250)};
            parameters[0].Value = AUTOID;
            DbHelper dbh = new DbHelper();
            DbCommand cmd = dbh.GetSqlStringCommond(strSql.ToString());
            cmd.Parameters.Add(parameters[0]);
            dbh.ExecuteNonQuery(cmd);
        }
        /// <summary>
        /// 删除满足条件的数据
        /// </summary>
        public void DeleteWhere(string whereStr)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from TAB_FILESDB ");
            if (!String.IsNullOrEmpty(whereStr.Trim()))
                strSql.Append(" where " + whereStr);

            DbHelperOra.ExecuteSql(strSql.ToString());
        }



        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public GMS.Model.FilesDB GetModel(string AUTOID)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select AUTOID,DEPT,CREATOR,TITLE,FILENO,CREATEDT,FILETYPE,BELONGID,BELONGTABLE,FILECONTENT,FILENAME,FILEPATH,FILESUFFIX,UNIQUENO,FLAG,UPDATOR,UPDATEDT,ATTRIBUTE1,ATTRIBUTE2,CITYCODE from TAB_FILESDB ");
            strSql.Append(" where AUTOID=:AUTOID ");
            OracleParameter[] parameters = {
					new OracleParameter(":AUTOID", OracleType.VarChar,50)};
            parameters[0].Value = AUTOID;

            GMS.Model.FilesDB model = new GMS.Model.FilesDB();
            DataSet ds = DbHelperOra.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                model.AUTOID = ds.Tables[0].Rows[0]["AUTOID"].ToString();
                model.DEPT = ds.Tables[0].Rows[0]["DEPT"].ToString();
                model.CREATOR = ds.Tables[0].Rows[0]["CREATOR"].ToString();
                model.TITLE = ds.Tables[0].Rows[0]["TITLE"].ToString();
                model.FILENO = ds.Tables[0].Rows[0]["FILENO"].ToString();
                if (ds.Tables[0].Rows[0]["CREATEDT"].ToString() != "")
                {
                    model.CREATEDT = DateTime.Parse(ds.Tables[0].Rows[0]["CREATEDT"].ToString());
                }
                model.FILETYPE = ds.Tables[0].Rows[0]["FILETYPE"].ToString();
                model.BELONGID = ds.Tables[0].Rows[0]["BELONGID"].ToString();
                model.BELONGTABLE = ds.Tables[0].Rows[0]["BELONGTABLE"].ToString();
                if (ds.Tables[0].Rows[0]["FILECONTENT"].ToString() != "")
                {
                    model.FILECONTENT = (byte[])ds.Tables[0].Rows[0]["FILECONTENT"];
                }
                model.FILENAME = ds.Tables[0].Rows[0]["FILENAME"].ToString();
                model.FILEPATH = ds.Tables[0].Rows[0]["FILEPATH"].ToString();
                model.FILESUFFIX = ds.Tables[0].Rows[0]["FILESUFFIX"].ToString();
                model.UNIQUENO = ds.Tables[0].Rows[0]["UNIQUENO"].ToString();
                model.FLAG = ds.Tables[0].Rows[0]["FLAG"].ToString();
                model.UPDATOR = ds.Tables[0].Rows[0]["UPDATOR"].ToString();
                if (ds.Tables[0].Rows[0]["UPDATEDT"].ToString() != "")
                {
                    model.UPDATEDT = DateTime.Parse(ds.Tables[0].Rows[0]["UPDATEDT"].ToString());
                }
                model.ATTRIBUTE1 = ds.Tables[0].Rows[0]["ATTRIBUTE1"].ToString();
                model.ATTRIBUTE2 = ds.Tables[0].Rows[0]["ATTRIBUTE2"].ToString();
                model.CITYCODE = ds.Tables[0].Rows[0]["CITYCODE"].ToString();
                return model;
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 根据相关表及相关ID得到一个对象实体
        /// </summary>
        public GMS.Model.FilesDB GetModel(string BELONGTABLE, string BELONGID)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select AUTOID,DEPT,CREATOR,TITLE,FILENO,CREATEDT,FILETYPE,BELONGID,BELONGTABLE,FILECONTENT,FILENAME,FILEPATH,FILESUFFIX,UNIQUENO,FLAG,UPDATOR,UPDATEDT,ATTRIBUTE1,ATTRIBUTE2,CITYCODE from TAB_FILESDB ");
            strSql.Append(" where upper(BELONGTABLE)=upper(:BELONGTABLE) and BELONGID=:BELONGID");
            OracleParameter[] parameters = {
					new OracleParameter(":BELONGTABLE", OracleType.VarChar,50),
                    new OracleParameter(":BELONGID", OracleType.VarChar,50)};
            parameters[0].Value = BELONGTABLE;
            parameters[1].Value = BELONGID;

            GMS.Model.FilesDB model = new GMS.Model.FilesDB();
            DataSet ds = DbHelperOra.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                model.AUTOID = ds.Tables[0].Rows[0]["AUTOID"].ToString();
                model.DEPT = ds.Tables[0].Rows[0]["DEPT"].ToString();
                model.CREATOR = ds.Tables[0].Rows[0]["CREATOR"].ToString();
                model.TITLE = ds.Tables[0].Rows[0]["TITLE"].ToString();
                model.FILENO = ds.Tables[0].Rows[0]["FILENO"].ToString();
                if (ds.Tables[0].Rows[0]["CREATEDT"].ToString() != "")
                {
                    model.CREATEDT = DateTime.Parse(ds.Tables[0].Rows[0]["CREATEDT"].ToString());
                }
                model.FILETYPE = ds.Tables[0].Rows[0]["FILETYPE"].ToString();
                model.BELONGID = ds.Tables[0].Rows[0]["BELONGID"].ToString();
                model.BELONGTABLE = ds.Tables[0].Rows[0]["BELONGTABLE"].ToString();
                if (ds.Tables[0].Rows[0]["FILECONTENT"].ToString() != "")
                {
                    model.FILECONTENT = (byte[])ds.Tables[0].Rows[0]["FILECONTENT"];
                }
                model.FILENAME = ds.Tables[0].Rows[0]["FILENAME"].ToString();
                model.FILEPATH = ds.Tables[0].Rows[0]["FILEPATH"].ToString();
                model.FILESUFFIX = ds.Tables[0].Rows[0]["FILESUFFIX"].ToString();
                model.UNIQUENO = ds.Tables[0].Rows[0]["UNIQUENO"].ToString();
                model.FLAG = ds.Tables[0].Rows[0]["FLAG"].ToString();
                model.UPDATOR = ds.Tables[0].Rows[0]["UPDATOR"].ToString();
                if (ds.Tables[0].Rows[0]["UPDATEDT"].ToString() != "")
                {
                    model.UPDATEDT = DateTime.Parse(ds.Tables[0].Rows[0]["UPDATEDT"].ToString());
                }
                model.ATTRIBUTE1 = ds.Tables[0].Rows[0]["ATTRIBUTE1"].ToString();
                model.ATTRIBUTE2 = ds.Tables[0].Rows[0]["ATTRIBUTE2"].ToString();
                model.CITYCODE = ds.Tables[0].Rows[0]["CITYCODE"].ToString();

                return model;
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select AUTOID,DEPT,CREATOR,TITLE,FILENO,CREATEDT,FILETYPE,BELONGID,BELONGTABLE,FILECONTENT,FILENAME,FILEPATH,FILESUFFIX,UNIQUENO,FLAG,UPDATOR,UPDATEDT,ATTRIBUTE1,ATTRIBUTE2,CITYCODE");
            strSql.Append(" FROM TAB_FILESDB ");
            if (!string.IsNullOrEmpty(strWhere))
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperOra.Query(strSql.ToString());
        }

        public DataSet GetListWithoutFileContent(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select AUTOID,CREATOR,CREATEDT,FILETYPE,BELONGID,BELONGTABLE,FILENAME,FILEPATH,FILESUFFIX,UNIQUENO,FLAG,UPDATOR,UPDATEDT,ATTRIBUTE1,ATTRIBUTE2 ");
            strSql.Append(" FROM TAB_FILESDB1 ");
            if (!string.IsNullOrEmpty(strWhere) && strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            DbHelper dbh = new DbHelper();
            DbCommand cmd = dbh.GetSqlStringCommond(strSql.ToString());
            return dbh.ExecuteDataSet(cmd);
        }

        /// <summary>
        /// 获得文件类别列表
        /// </summary>
        public DataTable GetFileTypeList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select distinct FILETYPE");
            strSql.Append(" FROM TAB_FILESDB ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperOra.DataTable(strSql.ToString());
        }



        /// <summary>
        /// 返回所有记录，但是不包含文件内容
        /// </summary>
        /// <param name="strWhere"></param>
        /// <returns></returns>
        public DataSet GetRecords(string strWhere, string orderField, string order)
        {
            string strSql = string.Empty;
            strSql += ("select AUTOID,DEPT,CREATOR,TITLE,FILENO,CREATEDT,FILETYPE,BELONGID,BELONGTABLE,FILENAME,FILEPATH,FILESUFFIX,UNIQUENO,FLAG,UPDATOR,UPDATEDT,ATTRIBUTE1,ATTRIBUTE2,CITYCODE");
            strSql += (" FROM TAB_FILESDB ");
            if (!string.IsNullOrEmpty(strWhere))
            {
                strSql += (" where " + strWhere);
            }
            if (!string.IsNullOrEmpty(orderField))
            {
                if (string.IsNullOrEmpty(order))
                {
                    order = "ASC";
                }
                else
                {
                    order = order.ToUpper();
                    if (order != "ASC" && order != "DESC")
                        order = "ASC";
                    strSql += (" order by " + orderField + " " + order);
                }
            }
            return DbHelperOra.Query(strSql.ToString());

        }

        /// <summary>
        /// 返回记录总数，使用有索引的Autoid字段
        /// </summary>
        public DataTable GetTotalRowsNum(string strWhere)
        {
            string strSql = "select count(AUTOID) from TAB_FILESDB";
            if (strWhere != null && strWhere.Trim() != "")
            {
                strSql += " where " + strWhere;
            }
            return DbHelperOra.DataTable(strSql);
        }

        protected string GetPageingSelectSql(string sql, int start, int end)
        {
            if (sql == null)
                return null;
            return "select * from ( select row_.*, rownum rownum_ from ("
                + sql + ") row_ where rownum <= " + end + ") where rownum_ > " + start;
        }

        /// <summary>
        /// 返回指定页
        /// </summary>
        /// <param name="strWhere">条件查询</param>
        /// <param name="orderField">按照该字段排序，可以为NULL</param> 
        /// <param name="order">"ASC"或"DESC"(顺序或逆序)</param>
        /// <param name="pageSize">一页大小</param>
        /// <param name="pageIndex">从0开始</param>
        /// <returns>DataSet中的Tables[0]为数据，Tables[1].Rows[0][0]为总行数</returns>
        public DataSet GetRecordsByPage(string strWhere, string orderField, string order, int pageSize, int pageIndex)
        {
            string strSql = string.Empty;
            strSql += "select AUTOID,DEPT,CREATOR,TITLE,FILENO,CREATEDT,FILETYPE,BELONGID,BELONGTABLE,FILENAME,FILEPATH,FILESUFFIX,UNIQUENO,FLAG,UPDATOR,UPDATEDT,ATTRIBUTE1,ATTRIBUTE2, CITYCODE";
            strSql += " FROM TAB_FILESDB ";

            if (!string.IsNullOrEmpty(strWhere))
            {
                strSql += (" where " + strWhere);
            }
            if (!string.IsNullOrEmpty(orderField))
            {
                if (string.IsNullOrEmpty(order))
                {
                    order = "ASC";
                }
                else
                {
                    order = order.ToUpper();
                    if (order != "ASC" && order != "DESC")
                        order = "ASC";
                    strSql += (" order by " + orderField + " " + order);
                }
            }

            int start = pageSize * pageIndex;
            int end = start + pageSize;
            DataTable dt = DbHelperOra.DataTable(GetPageingSelectSql(strSql, start, end));
            DataTable dtTotalRowsNum = GetTotalRowsNum(strWhere);
            DataSet ds = new DataSet();
            ds.Tables.Add(dt);
            ds.Tables.Add(dtTotalRowsNum);
            return ds;
        }

        /// <summary>
        /// 获得某一张表的多个文件路径列表
        /// </summary>
        public List<string> GetFilePathList(string tableName, string ids)
        {
            List<string> filePaths = new List<string>();
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select FILEPATH,UNIQUENO,FILENAME");
            strSql.Append(" FROM TAB_FILESDB WHERE BELONGTABLE='" + tableName.ToUpper() + "'");
            if (!string.IsNullOrEmpty(ids.Trim()))
            {
                strSql.Append(" AND BELONGID IN (" + ids + ")");
            }
            DataTable dt = DbHelperOra.DataTable(strSql.ToString());
            foreach (DataRow row in dt.Rows)
                filePaths.Add(row["FILEPATH"].ToString() + row["UNIQUENO"].ToString() + row["FILENAME"].ToString());
            return filePaths;
        }


        /*
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        {
            OracleParameter[] parameters = {
                    new OracleParameter(":tblName", OracleType.VarChar, 255),
                    new OracleParameter(":fldName", OracleType.VarChar, 255),
                    new OracleParameter(":PageSize", OracleType.Number),
                    new OracleParameter(":PageIndex", OracleType.Number),
                    new OracleParameter(":IsReCount", OracleType.Clob),
                    new OracleParameter(":OrderType", OracleType.Clob),
                    new OracleParameter(":strWhere", OracleType.VarChar,1000),
                    };
            parameters[0].Value = "TAB_FILESDB";
            parameters[1].Value = "ID";
            parameters[2].Value = PageSize;
            parameters[3].Value = PageIndex;
            parameters[4].Value = 0;
            parameters[5].Value = 0;
            parameters[6].Value = strWhere;	
            return DbHelperOra.RunProcedure("UP_GetRecordByPage",parameters,"ds");
        }*/

        /// <summary>
        /// 
        /// </summary>
        public GMS.Model.FilesDB GetModelWithoutFileContent(string AUTOID)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select AUTOID,CREATOR,CREATEDT,FILETYPE,BELONGID,BELONGTABLE,FILENAME,FILEPATH,FILESUFFIX,UNIQUENO,FLAG,UPDATOR,UPDATEDT,ATTRIBUTE1,ATTRIBUTE2 from TAB_FILESDB1 ");
            strSql.Append(" where AUTOID=@AUTOID ");
            OleDbParameter[] parameters = {
					new OleDbParameter("@AUTOID", OleDbType.VarChar,250)};
            parameters[0].Value = AUTOID;

            GMS.Model.FilesDB model = new GMS.Model.FilesDB();
            DbHelper dbh = new DbHelper();
            DbCommand cmd = dbh.GetSqlStringCommond(strSql.ToString());
            cmd.Parameters.Add(parameters[0]);
            DataSet ds = dbh.ExecuteDataSet(cmd);
            if (ds.Tables[0].Rows.Count > 0)
            {
                model.AUTOID = ds.Tables[0].Rows[0]["AUTOID"].ToString();
                model.CREATOR = ds.Tables[0].Rows[0]["CREATOR"].ToString();
                if (ds.Tables[0].Rows[0]["CREATEDT"].ToString().Trim() != "")
                {
                    model.CREATEDT = DateTime.Parse(ds.Tables[0].Rows[0]["CREATEDT"].ToString());
                }
                model.FILETYPE = ds.Tables[0].Rows[0]["FILETYPE"].ToString();
                model.BELONGID = ds.Tables[0].Rows[0]["BELONGID"].ToString();
                model.BELONGTABLE = ds.Tables[0].Rows[0]["BELONGTABLE"].ToString();
                //if (ds.Tables[0].Rows[0]["FILECONTENT"].ToString() != "") {
                //    model.FILECONTENT = (byte[])ds.Tables[0].Rows[0]["FILECONTENT"];
                //}
                model.FILECONTENT = null;
                model.FILENAME = ds.Tables[0].Rows[0]["FILENAME"].ToString();
                model.FILEPATH = ds.Tables[0].Rows[0]["FILEPATH"].ToString();
                model.FILESUFFIX = ds.Tables[0].Rows[0]["FILESUFFIX"].ToString();
                model.UNIQUENO = ds.Tables[0].Rows[0]["UNIQUENO"].ToString();
                model.FLAG = ds.Tables[0].Rows[0]["FLAG"].ToString();
                model.UPDATOR = ds.Tables[0].Rows[0]["UPDATOR"].ToString();
  
                if (ds.Tables[0].Rows[0]["UPDATEDT"].ToString().Trim() != "")
                {
                    model.UPDATEDT = DateTime.Parse(ds.Tables[0].Rows[0]["UPDATEDT"].ToString());
                }
                model.ATTRIBUTE1 = ds.Tables[0].Rows[0]["ATTRIBUTE1"].ToString();
                model.ATTRIBUTE2 = ds.Tables[0].Rows[0]["ATTRIBUTE2"].ToString();
                return model;
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public List<GMS.Model.FilesDB> GetModelListWithoutFileContent(ArrayList autoids)
        {
            List<GMS.Model.FilesDB> res = new List<GMS.Model.FilesDB>();
            for (int i = 0; i < autoids.Count; ++i)
            {
                res.Add(GetModelWithoutFileContent(autoids[i].ToString()));
            }
            return res;
        }

        public List<GMS.Model.FilesDB> GetModelListWithoutFileContent(string strWhere)
        {
            List<GMS.Model.FilesDB> res = new List<GMS.Model.FilesDB>();
            string strSql = "select AUTOID,DEPT,CREATOR,TITLE,FILENO,CREATEDT,FILETYPE,BELONGID,BELONGTABLE,FILECONTENT,FILENAME,FILEPATH,FILESUFFIX,UNIQUENO,FLAG,UPDATOR,UPDATEDT,ATTRIBUTE1,ATTRIBUTE2,CITYCODE from TAB_FILESDB ";
            if (!string.IsNullOrEmpty(strWhere) && strWhere.Trim() != null)
            {
                strSql = strSql + " where " + strWhere;
            }

            DataTable dt = DbHelperOra.DataTable(strSql.ToString());

            foreach (DataRow row in dt.Rows)
            {
                FilesDB model = new FilesDB();
                model.AUTOID = row["AUTOID"].ToString();
                model.DEPT = row["DEPT"].ToString();
                model.CREATOR = row["CREATOR"].ToString();
                model.TITLE = row["TITLE"].ToString();
                model.FILENO = row["FILENO"].ToString();
                if (row["CREATEDT"].ToString() != "")
                {
                    model.CREATEDT = DateTime.Parse(row["CREATEDT"].ToString());
                }
                model.FILETYPE = row["FILETYPE"].ToString();
                model.BELONGID = row["BELONGID"].ToString();
                model.BELONGTABLE = row["BELONGTABLE"].ToString();
                if (row["FILECONTENT"].ToString() != "")
                {
                    model.FILECONTENT = (byte[])row["FILECONTENT"];
                }
                model.FILENAME = row["FILENAME"].ToString();
                model.FILEPATH = row["FILEPATH"].ToString();
                model.FILESUFFIX = row["FILESUFFIX"].ToString();
                model.UNIQUENO = row["UNIQUENO"].ToString();
                model.FLAG = row["FLAG"].ToString();
                model.UPDATOR = row["UPDATOR"].ToString();
                if (row["UPDATEDT"].ToString() != "")
                {
                    model.UPDATEDT = DateTime.Parse(row["UPDATEDT"].ToString());
                }
                model.ATTRIBUTE1 = row["ATTRIBUTE1"].ToString();
                model.ATTRIBUTE2 = row["ATTRIBUTE2"].ToString();
                model.CITYCODE = row["CITYCODE"].ToString();
                res.Add(model);
            }
            return res;
        }





        /// <summary>
        /// 更新文件信息，不更新文件内容
        /// </summary>
        public void UpdateWithoutFileContent(GMS.Model.FilesDB model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update TAB_FILESDB set ");
            strSql.Append("DEPT=:DEPT,");
            strSql.Append("CREATOR=:CREATOR,");
            strSql.Append("TITLE=:TITLE,");
            strSql.Append("FILENO=:FILENO,");
            strSql.Append("CREATEDT=:CREATEDT,");
            strSql.Append("FILETYPE=:FILETYPE,");
            strSql.Append("BELONGID=:BELONGID,");
            strSql.Append("BELONGTABLE=:BELONGTABLE,");
            strSql.Append("FILENAME=:FILENAME,");
            strSql.Append("FILEPATH=:FILEPATH,");
            strSql.Append("FILESUFFIX=:FILESUFFIX,");
            strSql.Append("UNIQUENO=:UNIQUENO,");
            strSql.Append("FLAG=:FLAG,");
            strSql.Append("UPDATOR=:UPDATOR,");
            strSql.Append("UPDATEDT=:UPDATEDT,");
            strSql.Append("ATTRIBUTE1=:ATTRIBUTE1,");
            strSql.Append("ATTRIBUTE2=:ATTRIBUTE2,");
            strSql.Append("CITYCODE=:CITYCODE");
            strSql.Append(" where AUTOID=:AUTOID ");
            OracleParameter[] parameters = {
					new OracleParameter(":AUTOID", OracleType.VarChar,30),
					new OracleParameter(":DEPT", OracleType.VarChar,100),
					new OracleParameter(":CREATOR", OracleType.VarChar,50),
					new OracleParameter(":TITLE", OracleType.VarChar,100),
					new OracleParameter(":FILENO", OracleType.VarChar,50),
					new OracleParameter(":CREATEDT", OracleType.DateTime),
					new OracleParameter(":FILETYPE", OracleType.VarChar,20),
					new OracleParameter(":BELONGID", OracleType.VarChar,30),
					new OracleParameter(":BELONGTABLE", OracleType.VarChar,100),
					new OracleParameter(":FILENAME", OracleType.VarChar,300),
					new OracleParameter(":FILEPATH", OracleType.VarChar,400),
					new OracleParameter(":FILESUFFIX", OracleType.VarChar,20),
					new OracleParameter(":UNIQUENO", OracleType.VarChar,100),
					new OracleParameter(":FLAG", OracleType.Char,1),
					new OracleParameter(":UPDATOR", OracleType.VarChar,50),
					new OracleParameter(":UPDATEDT", OracleType.DateTime),
					new OracleParameter(":ATTRIBUTE1", OracleType.VarChar,100),
					new OracleParameter(":ATTRIBUTE2", OracleType.VarChar,100),
                    new OracleParameter(":CITYCODE", OracleType.VarChar,30)};
            parameters[0].Value = GetValidValue(model.AUTOID);
            parameters[1].Value = GetValidValue(model.DEPT);
            parameters[2].Value = GetValidValue(model.CREATOR);
            parameters[3].Value = GetValidValue(model.TITLE);
            parameters[4].Value = GetValidValue(model.FILENO);
            parameters[5].Value = GetValidValue(model.CREATEDT);
            parameters[6].Value = GetValidValue(model.FILETYPE);
            parameters[7].Value = GetValidValue(model.BELONGID);
            parameters[8].Value = GetValidValue(model.BELONGTABLE);
            parameters[9].Value = GetValidValue(model.FILENAME);
            parameters[10].Value = GetValidValue(model.FILEPATH);
            parameters[11].Value = GetValidValue(model.FILESUFFIX);
            parameters[12].Value = GetValidValue(model.UNIQUENO);
            parameters[13].Value = GetValidValue(model.FLAG);
            parameters[14].Value = GetValidValue(model.UPDATOR);
            parameters[15].Value = GetValidValue(model.UPDATEDT);
            parameters[16].Value = GetValidValue(model.ATTRIBUTE1);
            parameters[17].Value = GetValidValue(model.ATTRIBUTE2);
            parameters[18].Value = GetValidValue(model.CITYCODE);

            DbHelperOra.ExecuteSql(strSql.ToString(), parameters);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="lsImgs"></param>
        /// <param name="strdbID"></param>
        /// <returns></returns>
        public int AddFilsDB(List<GMS.Model.FilesDB> lsImgs, string strdbID)
        {
            DbHelper dbh = new DbHelper();
            Trans tx = new Trans();
            try
            {
                string sLogContext = string.Empty;
                string strPath = string.Empty;
                string strFileName = string.Empty;
                string strFileSuffix = string.Empty;
                for (int i = 0; i < lsImgs.Count; ++i)
                {
                    GMS.Model.FilesDB model = (GMS.Model.FilesDB)lsImgs[i];
                    model.BELONGID = strdbID;
                    StringBuilder strSql = new StringBuilder();
                    strSql.Append("insert into TAB_FILESDB1(");
                    strSql.Append("CREATOR,CREATEDT,FILETYPE,BELONGID,BELONGTABLE,FILENAME,FILEPATH,FILESUFFIX,UNIQUENO,FLAG,UPDATOR,UPDATEDT,ATTRIBUTE1,ATTRIBUTE2)");
                    strSql.Append(" values (");
                    strSql.Append("@CREATOR,@CREATEDT,@FILETYPE,@BELONGID,@BELONGTABLE,@FILENAME,@FILEPATH,@FILESUFFIX,@UNIQUENO,@FLAG,@UPDATOR,@UPDATEDT,@ATTRIBUTE1,@ATTRIBUTE2)");
                    //to_date(:CREATEDT,'YYYY-MM-DD HH24:MI:SS')to_date(:UPDATEDT,'YYYY-MM-DD HH24:MI:SS')
                    OleDbParameter[] parameters = {
					//new OracleParameter(":AUTOID", OracleType.VarChar,20),
					new OleDbParameter("@CREATOR", OleDbType.VarChar,250),
					new OleDbParameter("@CREATEDT", OleDbType.VarChar,250),
					new OleDbParameter("@FILETYPE", OleDbType.VarChar,250),
					new OleDbParameter("@BELONGID", OleDbType.VarChar,250),
					new OleDbParameter("@BELONGTABLE", OleDbType.VarChar,250),
					new OleDbParameter("@FILENAME", OleDbType.VarChar,250),
					new OleDbParameter("@FILEPATH", OleDbType.VarChar,250),
					new OleDbParameter("@FILESUFFIX", OleDbType.VarChar,250),
					new OleDbParameter("@UNIQUENO", OleDbType.VarChar,250),
					new OleDbParameter("@FLAG", OleDbType.VarChar,250),
                    new OleDbParameter("@UPDATOR", OleDbType.VarChar,250),
                    new OleDbParameter("@UPDATEDT", OleDbType.VarChar,250),
					new OleDbParameter("@ATTRIBUTE1", OleDbType.VarChar,250),
					new OleDbParameter("@ATTRIBUTE2", OleDbType.VarChar,250)
            };
                    //parameters[0].Value = model.AUTOID;
                    parameters[0].Value = model.CREATOR;
                    parameters[1].Value = model.CREATEDT.ToString();
                    parameters[2].Value = model.FILETYPE;
                    parameters[3].Value = model.BELONGID;
                    parameters[4].Value = model.BELONGTABLE;
                    parameters[5].Value = model.FILENAME;
                    parameters[6].Value = model.FILEPATH;
                    parameters[7].Value = model.FILESUFFIX;
                    parameters[8].Value = model.UNIQUENO;
                    parameters[9].Value = model.FLAG;
                    parameters[10].Value = model.UPDATOR;
                    parameters[11].Value = model.UPDATEDT.ToString();
                    parameters[12].Value = model.ATTRIBUTE1;
                    parameters[13].Value = model.ATTRIBUTE2;

                    /*strSql = " insert into tab_filesdb(dept,creator,title,fileno,createdt,"
                        + "filetype,belongid,belongtable,filecontent,filename,filepath,filesuffix,"
                        + "uniqueno,flag,updator,updatedt) "
                        + "values('" + files.DEPT + "','" + files.CREATOR + "','" + files.TITLE
                        + "','" + files.FILENO + "',to_date('" + files.CREATEDT + "','YYYY-MM-DD HH24:MI:SS'),'" + files.FILETYPE
                        + "','" + files.BELONGID + "','" + files.BELONGTABLE + "',:filecontent,'" + files.FILENAME + "','" + files.FILEPATH + "','" + files.FILESUFFIX
                        + "','" + files.UNIQUENO + "','" + files.FLAG + "','" + files.UPDATOR
                        + "',to_date('" + files.UPDATEDT + "','YYYY-MM-DD HH24:MI:SS'))";
                    OracleParameter[] parameters = {
                    new OracleParameter(":filecontent", OracleType.Blob)};
                    */
                    //parameters[0].Value = imageb;
                    //PrepareCommand(comm, connection, null, SQLString, cmdParms);
                    //int rows = comm.ExecuteNonQuery();
                    //comm.Parameters.Clear();to_date('2009-10-23 22:50:22','YYYY-MM-DD HH24:MI:SS'),
                    //return rows;
                    DbCommand cmd = dbh.GetSqlStringCommond(strSql.ToString());
                    //dbh.PrepareCommand(cmd, tx.DbConnection, tx.DbTrans, cmd.CommandText, parameters);
                    cmd.ExecuteNonQuery();
                }
                tx.Commit();//提交事务 
                //sLogContext = strAddUser;
                //写入日志文件
                //LogHelper.ERRInstance.WriteErrToLog(LOGFILENAME, sLogContext, true);
                return 1;
            }
            catch (System.Data.Common.DbException E)
            {
                tx.RollBack();//回滚事务 
                return 0;
            }
            finally
            {

            }
        }
        #endregion  成员方法
    }
}